<?php
if (!defined('ABSPATH')) {
	define( 'ABSPATH', dirname(dirname(__FILE__)) . '/' );
}

require_once ABSPATH . 'dr-config.php';

require_once ABSPATH . DRINC . '/dr-base.php';
require_once ABSPATH . DRINC . '/dr-functions.php';
require_once ABSPATH . DRINC . '/dr-fun-users.php';
require_once ABSPATH . DRINC . '/dr-themes.php';
require_once ABSPATH . DRINC . '/dr-smarty.php';
require_once ABSPATH . DRINC . '/dr-page-check-login.php';
require_once ABSPATH . DRINC . '/mygravatar.php';

$user_id = isset($_GET['uid'])?$_GET['uid']:0;
$display = isset($_GET['display'])?$_GET['display']:"";
$tab     = isset($_GET['tab'])?$_GET['tab']:'';
$msg_id  = isset($_GET['msg_id']) ? $_GET['msg_id'] : 0;
$tabs    = array('message','activity','question','listen','reply','vote','statistic');
$day     = isset($_GET['day']) ? $_GET['day'] : 15;

if(!in_array($day, array(3,7,15,30)))
	$day=7;

# ============ #
# 获得用户的相关信息
$user = dr_get_user_profile($user_id);
# ============ #

$login_id=dr_is_login_on();

if(empty($tab))
{
	if($user_id==$login_id)
		$tab='message';
	else 
		$tab='activity';
}

if(in_array($tab, $tabs)) {
	$posts = array(
		'action' => 'get_user_info',
		'user_id'=>$user_id,
		'login_id'=>$login_id,
		'tab'=>$tab,
		'msg_id'=>$msg_id,
		'day' =>$day
	);
} else {
	$redirect=BASE_HOSTPATH . "dr-includes/dr-404error.php";
	header("Location: $redirect");
}

$result = dr_server_request('dr-app-users.php', $posts);
$result_array=json_decode($result,1);

//var_dump($result_array);

dr_to_html($result_array);
$smarty->assign('tab',$tab);
$smarty->assign('uid',$user_id);

if($tab=='message')
{
	//var_dump($result_array);
	if($display=="yes")
		$smarty->assign('display','yes');
	else
		$smarty->assign('display','no');
		$smarty->assign('message',$result_array);
}
else if($tab=='activity')
{
	
	$smarty->assign('activity',$result_array);
}

else if($tab=='question')
{
	//var_dump($result_array['tag']);
	$smarty->assign('taglist',$result_array['tag']);
	$smarty->assign('questions',$result_array['question']);
	$smarty->assign('mark',$result_array['mark']);
}

else if($tab=='listen')
{
	//var_dump($result_array['listening']);
	$smarty->assign('listening',$result_array['listening']);
	$smarty->assign('listened',$result_array['listened']);
}

else if($tab=='reply')
{
	$smarty->assign('answer',$result_array['answer']);
	$smarty->assign('comment',$result_array['comment']);
}

else if($tab=='vote')
{
	
	$smarty->assign('question_vote',$result_array['question_vote']);
	$smarty->assign('answer_vote',$result_array['answer_vote']);
	$smarty->assign('comment_vote',$result_array['comment_vote']);

}

else if($tab=='statistic')
{
	//var_dump($result_array['statistic'][0]);
	$smarty->assign('statistic',$result_array['statistic'][0]);
}


$smarty->assign('page_title', 'User ' . $user['username'] . ' - iDaren');
$avatar = (string) new MyGravatar($user['email'], 128);
$smarty->assign('avatar', $avatar);
$smarty->assign('user', $user);

$smarty->assign('is_login',$login_id);
$smarty->assign('login_id',$login_id);
$smarty->assign('display_id',$user_id);
$smarty->assign('display',$display);
$smarty->assign('day',$day);






$content = array();
$content['top_navs'] = get_page_top_navigation();
$content['menus'] = get_page_menus('users');
$content['tabs'] = get_page_tabs('user_info', '');
$content['tabs']['title'] .= ' - ' . $user['username'];

$content['tabs2'] = get_page_tabs('user_info_detail', $tab);
foreach ($content['tabs2']['tabs'] as $key => &$tab2) {
	$tab2['link'] = sprintf($tab2['link'], $user_id);
}

$smarty->assign('content', $content);



$smarty->display('admin/userinfo.tpl');

